package uuid

import (
	"encoding/binary"
	"math/rand"
	"time"

	"gitee.com/les49/esgo/encoding/base58"
)

const (
	APP_ID_STRING_LEN = 16
)

func GenerateAppId(strLen uint32) string {

	rand.New(rand.NewSource(time.Now().Unix()))

	appId := rand.Uint64()
	buf := make([]byte, binary.MaxVarintLen64)
	binary.BigEndian.PutUint64(buf, appId)

	strAppId := base58.Encode(buf)
	if strLen == 0 {
		strLen = APP_ID_STRING_LEN
	}
	strAppId = toLen(strAppId, int(strLen))

	return strAppId
}
